package runesim.testing;

/**
 * Basic and complex printing methods for the server
 * @author Lemons
 * @version 1
 */
public class Print {
	
	/**
	 * Mimic the method "System.out.println" in a shorter manner
	 * @param message Message to display
	 */
	public static void println(String message) {
		System.out.println(message);
	}
	
	/**
	 * Mimic the method "System.out.print" in a shorter manner
	 * @param message Message to display
	 */
	public static void print(String message) {
		System.out.print(message);
	}
	
	/**
	 * Simplifys printing important information. Use " [BR] " with spaces to create a break.
	 * @param message Message to display
	 * @param title to include. null if none
	 */
	public static void notice(String message, String title) {
		int length = 0;
		message = message.replace("<br />", " [BR] ");
		String[] noticetxt = message.split(" ");
		if (title != null) {
			length = (int)(Math.floor((79 - (title.length() + 2)) / 2));
			if (((79 - (title.length() + 2)) & 1) != 0) {
				for (int i = length; i > 0; i--) print ("*");
				print(" " + title + " ");
				for (int i = length; i > 0; i--) print ("*");
				println("*");
			} else {
				for (int i = length; i > 0; i--) print ("*");
				print(" " + title + " ");
				for (int i = length - 1; i > 0; i--) print ("*");
				println("*");
			}
			length = 0;
		} else {
			println("*******************************************************************************");
		}
		boolean cont = true;
		int wc = 0;
		while (cont) {
			print("* ");
			try {
				while (length + noticetxt[wc].length() + 1 <= 75 && noticetxt.length > wc) {
					if (!noticetxt[wc].contains("[BR]")) {
						print(noticetxt[wc] + " ");
				    length += noticetxt[wc].length() + 1;
					  wc++;
					} else { wc++; break; }
				}
			} catch (Exception e) { }
			for (int i = (75 - length); i > 0; i--) print(" ");
			println(" *");
			if (noticetxt.length <= wc) cont = false;
			
			length = 0;
		}
		println("\r*******************************************************************************");
	}

	/**
	 * Error reporting, without	an exception.
	 * @param message
	 */
	public static void error(String message, String Class, String Method) {
		Print.println("");
		notice("A error was found in the following method: [BR]	 " + Class + " [BR]  " + Method + " [BR] User message: [BR] " + message +".", null);
	}

	/**
	 * Error reporting, with an exception.
	 * @param message
	 * @param Class Class, including package (EX: skills.Woodcutting)
	 * @param Method Method that the error happened in.
	 * @param e Exception to print.
	 */
	public static void error(String message, String Class, String Method, Exception e) {
		Print.println("");
		notice("A error was found in the following method: [BR]	 " + Class + "." + Method + " [BR] User message: [BR] " + message, null);
		println("Exception was included:");
		e.printStackTrace();
	}
}
